package ke07.pm.reihe6;

import java.util.LinkedList;
import ke07.pm.template.*;

public class MyHundredItemBag implements HundredItemBag<Object> {

	LinkedList<Object> list = new LinkedList<Object>();

	@Override
	public boolean add(Object obj) {
		try {

			if (list.size() <= 100) {
				list.add(obj);
				return true;

			}

			return false;
		} catch (IllegalArgumentException e) {
			return false;
		}
	}

	@Override
	public boolean contains(Object obj) {

		return list.contains(obj);
	}

	@Override
	public int count(Object obj) {
		int counter = 0;
		for (int x = 0; x < list.size(); x++) {
			if (list.get(x).equals(obj)) {
				counter++;
			}
		}
		return counter;
	}

	@Override
	public boolean remove(Object obj) {
		if (obj == null) {
			throw new IllegalArgumentException();
		} else {
			while (!(count(obj) == 0)) {
				list.remove(obj);
			}
		}
		return true;
	}

	@Override
	public int size() {
		return list.size();

	}

	@Override
	public Object[] toArray() {

		return list.toArray();
	}

}
